package com.smart.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.common.utils.file.FileUtils;
import com.smart.system.domain.Employee;
import com.smart.system.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smart.system.mapper.AudioMapper;
import com.smart.system.domain.Audio;
import com.smart.system.service.IAudioService;

import java.io.IOException;
import java.io.InputStream;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author smart
 * @date 2025-01-07
 */
@Service
public class AudioServiceImpl extends ServiceImpl<AudioMapper, Audio> implements IAudioService {

    @Autowired
    private IEmployeeService employeeService;
    @Override
    public Page<Audio> getChatRecord(Page<Audio> toPage, Integer employeeId, Integer toEmployeeId) {
        Page<Audio> page = this.page(toPage, Wrappers.lambdaQuery());
        for (Audio record : page.getRecords()) {
            Integer empId = record.getEmployeeId();
            Employee employee = employeeService.selectEmployeeById(String.valueOf(empId));
            record.setName(employee.getName());
            record.setPhoto(employee.getPhoto());
//            String audio = record.getBody();
//            try {
//                FileUtils.saveInputStream(audio,record.getId(),"mp3","D://");
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
        }
        return page;
    }
}